package com.cn.zmc.design.factory;

public class FactoryMethod {

    public static void main(String[] args) {
        new MethodFactory1().getInstance(2).invoke();
    }

    public static interface MethodInterface {

        void invoke();
    }

    public static class MethodA implements MethodInterface {

        @Override
        public void invoke() {
            System.out.println("MethodA");
        }
    }

    public static class MethodB implements MethodInterface {

        @Override
        public void invoke() {
            System.out.println("MethodB");
        }
    }

    public static class MethodC implements MethodInterface {

        @Override
        public void invoke() {
            System.out.println("MethodC");
        }
    }

    public abstract static class Factory {

        public MethodInterface getInstance (int type) {
            commend();
            return getResult();
        }
        abstract MethodInterface getResult();


        public static void commend() {
            System.out.println("通用逻辑");
        }

    }

    public static class MethodFactory1 extends Factory {

        @Override
        MethodInterface getResult() {
            System.out.println("MethodFactory1");
            return new MethodA();
        }
    }

    public static class MethodFactory2 extends Factory {

        @Override
        MethodInterface getResult() {
            System.out.println("MethodFactory2");
            return new MethodB();
        }
    }

    public static class MethodFactory3 extends Factory {

        @Override
        MethodInterface getResult() {
            System.out.println("MethodFactory3");
            return new MethodC();
        }
    }

}
